home *** CD-ROM | disk | FTP | other *** search
/ User's Choice Windows CD / User's Choice Windows CD (CMS Software)(1993).iso / windows5 / vbterm.zip / RX.FRM (.txt) < prev    next >
Visual Basic Form  |  1991-08-31  |  8KB  |  136 lines

  1. Receive XMODEM
  2. Form1
  3. Label1
  4. Receving to file:
  5. filename
  6. filename
  7. Label4
  8. Receive Mode:
  9. filemode
  10. filemode
  11. Label2
  12. Bytes Received:
  13. rbytes
  14. rbytes
  15. Label3
  16. Errors: Recent/Total:
  17. CommandAbort
  18. Abort
  19. errors
  20. errors
  21. Form_Click
  22. Form_Paint
  23. serialbinary
  24. NextPacket
  25. checksum
  26. numbytes
  27. FileNumber
  28. filenameT
  29. textz
  30. SerialWrite
  31. GetTickCount/
  32. timeout
  33. SerialRead
  34. error_count
  35. WaitSOH
  36. rbytes_Click?
  37. filesize
  38. rbytes
  39. caption
  40.     interlock"
  41. interlo:
  42. ErrorsRecent
  43. ErrorsTotal
  44. errors
  45. ProcessError
  46. CommandAbort_Click
  47.     FlagAbort
  48. RXAsciiPut
  49. filemode
  50.    FILE
  51.  RX.FRM
  52.  This is the code to handle the XMODEM reception
  53.    Charles McGuinness [76701,11]
  54.    These define the various control characters used in receiving
  55.    XMODEM transferss
  56.  (R) Start of Header, indicates the start of a packeti
  57.  (R) End of Transmission, indicates the end of filee
  58.  (S) Acknowledge, indicates we received the block OK
  59.  (S) Back space, sent after CANs to clear the host I/P buffert
  60.  (S) Negative ACK, indicates a bad block
  61.  (S) CANcel, sent when the user aborts to stop transmitter
  62.  (R) Control Z, the padding character for the last block
  63.    Returns number of milliseconds since system boot 
  64.    Set when the user clicks on "abort" buttonm
  65. Form_Paint
  66.    This is the main reception routine!
  67.    Notes for future 
  68. . we should have a generalized read with timeout routine rather than
  69.    replicating the same code..
  70.  Number of the next packet
  71.  Temp var for computing checksum
  72.  Used to loop 1 to 128
  73.  Used to hold the data received
  74.  What file number to write toi
  75.  Used to get data from SerialRead
  76.  Used to time out transmitterR
  77.  How many bytes received so far?
  78.  Used to prevent re-entrancy
  79.  How many errors in a row?
  80.  How many errors since we started
  81.  How many bytes read from serial port?
  82.  If this routine is already running, exit...
  83. Unable to open "
  84.  Switch into binary communications
  85.    Send the other end a NAK character which should elicit the firstf
  86.    data packet
  87. 0 / 0"
  88.  Update the displayh
  89.  At this point in the loop, we're waiting for the next packetx
  90.  to arrive.o
  91.  If here, we just NAKed a bad packet.  Update the error stats,
  92.  and abort transfer if too bad. 
  93.  We'll permit up to 10 errors in a row before aborting.  There's
  94.  no limit on how many errors in total we'll allow.
  95.  Send a bunch of CANs to transmitter to tell it we're quiting,
  96. Too many errors"
  97.  Wait for SOH or EOT
  98.  Update error count...
  99.  Has the user clicked the abort button? 
  100.  Send 8 CANs (^X) and then 8 backspaces (^H)
  101.  OK, let's note what time it is, and start waiting...a
  102.  Have we been waiting for more than 10 seconds?i
  103.  Send a NAK (hopefully this will get the transmitter
  104.  going again), and tally our errorst
  105.    Did we get EOT?
  106.  Note for future: It is preferable to NAK the first EOT character,
  107.  force the transmitter to resend it, and make sure we get anothere
  108.  EOT.  This will cut down on false EOT detection.e
  109.  OK, we got the EOTE
  110.  Now we have the SOH, let's get the packet #
  111.  The first character after the SOH is the packet number.  Either
  112.  it's the one we want, in which case we'll continue, or its ther
  113.  the previous packet, which means the transmitter didn't see our
  114.  ack, or its completely different, which means either we're totallye
  115.  out of sync OR we've just seen a "false" SOH.  If its the previous 
  116.  packet, we'll ACK it (again) to get things moving
  117.  Not the packet we want?
  118.  The previous packet again??
  119.  get the packet 255-#.  After the packet number is sent, the complemento
  120.  of the packet number is sent for safety's sake...
  121.  Not the packet we want?
  122.  So far, so good.  Now, get the 128 bytes of data...
  123.  Finally, get the check sumc
  124.  Do the checksums match?
  125.  Yes, ACK the transmitter
  126.  ... write the data to the fileo
  127. Binary
  128.  ... update our statistics
  129.  No, NAK the transmitter
  130.  ... and update error statistics
  131. CommandAbort_Click
  132.    This routine sets the abort flag, which is checked in the main loop
  133. RXAsciiPut
  134.    This routine writes a buffer to a file, but filters out any
  135.    control-Zs from the text first.
  136.